﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using eschoolBO;

namespace ESCHOOL.admin
{
    public partial class WebForm25 : System.Web.UI.Page
    {
        Poll p1 = new Poll();
        polloption p2 = new polloption();
        protected void Page_Load(object sender, EventArgs e)
        {
            tb1.Visible = false; tb2.Visible = false;
            tb3.Visible = false; tb4.Visible = false;
        }

        protected void rbchoice_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (rbchoice.SelectedValue == "Three")
            {
                tb1.Visible = true; tb2.Visible = true; tb3.Visible = true;
            }
            if (rbchoice.SelectedValue == "Four")
            {
                tb1.Visible = true; tb2.Visible = true; tb3.Visible = true; tb4.Visible = true;
            }
        }

        protected void btnadd_Click(object sender, EventArgs e)
        {
            p1.poll_id = -99;
            p1.question = tbques.Text;
            p1.isdeleted = false;
            p1.SaveRecords();
            DataTable dt = p1.GetRecords(-99, "", true, false, " and ");
            if (rbchoice.SelectedValue == "Three")
            {
                string[] ans3 = new string[3];
                ans3[0] = tb1.Text;
                ans3[1] = tb2.Text;
                ans3[2] = tb3.Text;
                for (int i = 0; i < 3; i++)
                {
                    p2.option_id = -99;
                    p2.poll_id = Convert.ToInt64(dt.Rows[0]["poll_id"].ToString());
                    p2.answer = ans3[i];
                    p2.vote = 0;
                    p2.isdeleted = false;
                    p2.SaveRecords();
                }
            }
            if (rbchoice.SelectedValue == "Four")
            {
                string[] ans3 = new string[4];
                ans3[0] = tb1.Text;
                ans3[1] = tb2.Text;
                ans3[2] = tb3.Text;
                ans3[3] = tb4.Text;
                for (int i = 0; i < 4; i++)
                {
                    p2.option_id = -99;
                    p2.poll_id = Convert.ToInt64(dt.Rows[0]["poll_id"].ToString());
                    p2.answer = ans3[i];
                    p2.vote = 0;
                    p2.isdeleted = false;
                    p2.SaveRecords();
                }
            }

            
        }
    }
}
